package com.mywork.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciko.code.adapter.WorkActionMsgAdapter;
import com.ciko.code.base.BaseActicity;
import com.ciko.code.bean.GetPolicyActivitiesListEty;
import com.ciko.code.http.BaseResponse;
import com.ciko.code.http.HttpClient;
import com.ciko.code.http.Req.GetPolicyActivitiesListReq;
import com.ciko.code.views.PullListView;
import com.mywork.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 12154 on 2015/11/5.
 */
public class WorkActionActivity extends BaseActicity implements AdapterView.OnItemClickListener{

    private ImageView ivmsgNew;
    private TextView tvtitleNew;
    private TextView tvshortInfoNew;
    private PullListView lvzhengceMsg;
    private PullListView lvactionMsg;

    private WorkActionMsgAdapter workActionMsgAdapter1;
    private WorkActionMsgAdapter workActionMsgAdapter2;

    private List<GetPolicyActivitiesListEty> getPolicyActivitiesListReqListResult1 = new ArrayList<>();
    private List<GetPolicyActivitiesListEty> getPolicyActivitiesListReqListResult2 = new ArrayList<>();

    @Override
    protected void initTopBar() {
        setTitle("政策活动");
        enableNavLeftImg();
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_work_action);
    }

    @Override
    protected void initView() {
        lvactionMsg = findViewByID(R.id.lv_actionMsg);
        lvzhengceMsg = findViewByID(R.id.lv_zhengceMsg);
        tvshortInfoNew = findViewByID(R.id.tv_shortInfoNew);
        tvtitleNew = findViewByID(R.id.tv_titleNew);
        ivmsgNew = findViewByID(R.id.iv_msgNew);
    }

    @Override
    protected void initAdapter() {

    }

    @Override
    protected void initDates() {
        // 1:最新公告；2:政策;3:活动
        // TODO 成功
        HttpClient.getInstance(this).post(new GetPolicyActivitiesListReq("1", 0, 10), this);
        HttpClient.getInstance(this).post(new GetPolicyActivitiesListReq("2", 0, 10), this);
        HttpClient.getInstance(this).post(new GetPolicyActivitiesListReq("3", 0, 10), this);
    }

    @Override
    protected void initListener() {
        lvactionMsg.setOnItemClickListener(this);
        lvzhengceMsg.setOnItemClickListener(this);
    }

    @Override
    public void onResponseSuccess(BaseResponse<?> response, String tag) {
        super.onResponseSuccess(response, tag);

        List<GetPolicyActivitiesListEty> getPolicyActivitiesListReqListResult = (List<GetPolicyActivitiesListEty>) response.getReturnObject();

        if (getPolicyActivitiesListReqListResult != null) {


            switch (getPolicyActivitiesListReqListResult.get(0).getType()) {
                case "1":
                    GetPolicyActivitiesListEty getPolicyActivitiesListEty = getPolicyActivitiesListReqListResult.get(0);
                    loadImageUrl(ivmsgNew, getPolicyActivitiesListReqListResult.get(0).getCoverImg());
                    tvtitleNew.setText(getPolicyActivitiesListEty.getTitle());
                    tvshortInfoNew.setText(getPolicyActivitiesListEty.getShortIntro());
                    break;
                case "2":
                    workActionMsgAdapter1 = new WorkActionMsgAdapter(this, getPolicyActivitiesListReqListResult, R.layout.litem_list_work_action);
                    lvzhengceMsg.setAdapter(workActionMsgAdapter1);
                    break;
                case "3":
                    workActionMsgAdapter2 = new WorkActionMsgAdapter(this, getPolicyActivitiesListReqListResult, R.layout.litem_list_work_action);
                    lvactionMsg.setAdapter(workActionMsgAdapter2);
                    break;
            }


        }

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        GetPolicyActivitiesListEty getPolicyActivitiesListEty = (GetPolicyActivitiesListEty) parent.getAdapter().getItem(position);

        if(getPolicyActivitiesListEty.getHasHtml().equals("y")){
            Intent intent = new Intent(this, WebActivity.class);
            intent.putExtra("URL", getPolicyActivitiesListEty.getHtmlUrl());
            startActivity(intent);
        }

    }
}
